﻿using System;
using System.ServiceModel.Activation;
using BasicFrameworkDemo.IBLL;
using BasicFrameworkDemo.Model;
using BasicFrameworkDemo.Service.Model;
using BasicFrameworkDemo.ServicesContracts;

namespace BasicFrameworkDemo.Services
{
    public class Service1 : IService1
    {
        private readonly IAuthen authen;

        public Service1()
        {
        }

        public Service1(IAuthen authen)
        {
            this.authen = authen;
        }

        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public ServiceLoginResponse Login(ServiceLoginRequest loginRequest)
        {
             var loginResponse = authen.Login(new LoginRequest(){UserName = loginRequest.UserName,Password = loginRequest.Password});

            return new ServiceLoginResponse
                       {
                           Message = loginResponse.Status==1?"Successfully":loginResponse.ErrorMessage
                       };
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}
